<template>
    <list-layout>
        <div slot="search">
            <el-form :model="queryParams" :inline="true" ref="queryForm" label-width="88px">
                <!-- 项目名称 -->
                <el-form-item :label="$t('bommaterial.projectName')" prop="bomProjectName">
                    <el-input v-model="queryParams.bomProjectName" :placeholder="$t('public.placeholder',{placeholder: $t('bommaterial.projectName')})" clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <!-- 厂区 -->
                <el-form-item :label="$t('inspectionManagement.plantArea',{placeholder: $t('inspectionManagement.plantArea')})" prop="factoryName">
                    <el-select v-model="queryParams.factoryName" class="line_select" filterable size="small" reserve-keyword :placeholder="$t('public.inputPl')">
                        <el-option v-for="item in factoryOptions" :key="item.id" :label="item.plantName" :value="item.plantName">
                        </el-option>
                    </el-select>
                </el-form-item>
                <!-- 物料编号-->
                <el-form-item :label="$t('inventoryManagement.materialNo')" prop="materialCode">
                    <el-input v-model="queryParams.materialCode" :placeholder="$t('public.placeholder',{placeholder: $t('inventoryManagement.materialNo')})" clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <!-- 物料名称-->
                <el-form-item :label="$t('inventoryManagement.materialName')" prop="materialName">
                    <el-input v-model="queryParams.materialName" :placeholder="$t('public.placeholder',{placeholder: $t('inventoryManagement.materialName')})" clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item :label="$t('inspectionManagement.version')" prop="version">
                    <el-input v-model="queryParams.version" :placeholder="$t('public.placeholder',{placeholder: $t('inspectionManagement.version')})" clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="到货时间" prop="cpudt">
                    <el-date-picker style="width: 214px" v-model="queryParams.cpudt" size="small" value-format="yyyy-MM-dd" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <div style="display:flex;justify-content: center;">
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{$t('public.search')}}</el-button>
                <el-button icon="el-icon-refresh" class="resectBtn" size="mini" @click="resetQuery">{{$t('public.reset')}}</el-button>
            </div>
        </div>
        <div class="app-container">
            <div class="container-header">
                <div class="header-left">
                    {{$t('bommaterial.title')}}
                </div>
            </div>
            <el-row :gutter="10" class="table-action-wrap btnGroup" style="margin-top:5px;float:left">
                <el-col :span="1.5">
                    <el-button class="exportitemBtn" size="mini" @click="handleExport">
                        <img src="@/assets/images/icons/daochu.png" alt="">
                        {{$t('public.export')}}
                    </el-button>
                </el-col>
            </el-row>
            <div class="container-table">
                <el-table max-height="350" border stripe v-loading="loading" :data="typeList">
                    <el-table-column :label="$t('bommaterial.projectName')" align="left" prop="bomProjectName" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.materialNo')" align="left" prop="materialCode" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.materialName')" align="left" prop="materialName" :show-overflow-tooltip="true" />
                    <!-- <el-table-column :label="$t('inventoryManagement.maturity')" align="left" prop="maturity" :show-overflow-tooltip="true" /> -->
                    <el-table-column :label="$t('inspectionManagement.plantArea')" align="left" prop="factoryName" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('defectIncoming.totalMasterialBatch')" align="left" prop="countLot" :show-overflow-tooltip="true" />
                    <!-- <el-table-column :label="$t('inventoryManagement.incomingQuantity')" align="left" prop="batchAmount" :show-overflow-tooltip="true" /> -->
                    <el-table-column :label="$t('defectIncoming.useDecisionNum')" align="left" prop="qualifiedLot" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('defectIncoming.useDecisionNoNum')" align="left" prop="noQualifiedLot" :show-overflow-tooltip="true" />
                </el-table>

                <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" layout="total, sizes, prev, pager, next, jumper" />
            </div>

        </div>
    </list-layout>
</template>

<script>
import { getBomList } from '@/api/statistical/statistical.js'
import { listALLFactory } from '@/api/basic/factory'
//统计管理-BOM物料详情
export default {
    name: 'bommaterial',
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 总条数
            total: 0,
            // 字典表格数据
            typeList: [],
            // 日期范围
            dateRange: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                bomAnalyseId: this.$route.query.bomAnalyseId || '',
                factoryName: '',
                materialName: '',
                materialNo: '',
                cpudt: null,
            },
            factoryOptions: [], //厂区容器
        }
    },
    created() {
        this.getFactoryList()
        this.getList()
        console.log(this.$route.params)
    },
    methods: {
        /** 导出按钮操作 */
        handleExport() {
            let queryParams = {
                ...this.queryParams,
                beginTime: this.queryParams.cpudt
                    ? this.queryParams.cpudt[0]
                    : undefined,
                endTime: this.queryParams.cpudt
                    ? this.queryParams.cpudt[1]
                    : undefined,
                exportFlag: 1,
            }
            delete queryParams.cpudt
            getBomList(queryParams, 'arraybuffer').then((response) => {
                const aLink = document.createElement('a')
                var blob = new Blob([response])
                aLink.href = URL.createObjectURL(blob)
                console.log(aLink.href)
                aLink.setAttribute(
                    'download',
                    `BOM详情_${new Date().getTime()}.xlsx`
                ) // 设置下载文件名称
                document.body.appendChild(aLink)
                aLink.click()
                document.body.removeChild(aLink)
            })
        },
        /** 查询字典类型列表 */
        getList() {
            this.loading = true
            let queryParams = {
                ...this.queryParams,
                beginTime: this.queryParams.cpudt
                    ? this.queryParams.cpudt[0]
                    : undefined,
                endTime: this.queryParams.cpudt
                    ? this.queryParams.cpudt[1]
                    : undefined,
            }
            delete queryParams.cpudt
            getBomList(queryParams).then((response) => {
                this.typeList = response.rows
                this.total = response.total
                this.loading = false
            })
        },
        // 获取厂区数据
        getFactoryList() {
            listALLFactory().then((res) => {
                this.factoryOptions = res.data
            })
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
    },
}
</script>
<style lang="scss" scoped>
::v-deep .el-card {
    padding-top: 20px;
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    padding-bottom: 20px;
}
::v-deep .el-aside {
    padding: 0;
    margin-bottom: 0;
}
.content-style {
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    background-color: white;
    margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
    background: #fff;
    border: 1px solid #0b7be3;
    color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
    background: #fff;
    border: 1px solid #ededf2;
    color: #666666;
}
.header-left {
    float: left;
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    line-height: 40px;
    display: flex;
    justify-content: center;
    border-bottom: 2px solid #0b7be3;
}
.header-right {
    float: right;
}
.container-header {
    float: left;
    width: 100%;
    border-bottom: 1px solid #ededf2;
}
.container-table {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.mb8 {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.drawer-footer {
    display: flex;
    position: relative;
    z-index: 9999;
    bottom: -40px;
    height: 40px;
    justify-content: center;
    width: 100%;
}
.drawer-close {
    background: #f7f8fa;
    border-color: #f7f8fa;
}
</style>
